# @FileName  :  agent.py
# @Time      :  2025/7/28 22:34
# @Author    :  Ayanami
# @info      :  Agent相关的Pydantic模型

from datetime import date, datetime
from typing import Optional, List
from pydantic import BaseModel, Field


class AgentBase(BaseModel):
    """Agent基础模型"""
    name: str = Field(..., max_length=100, description="机构名称")
    credit_code: str = Field(..., max_length=20, description="统一社会信用代码")
    license_expire: date = Field(..., description="执照有效期")
    business_scope: str = Field(..., description="经营范围")
    legal_person: str = Field(..., max_length=50, description="法人")
    phone: str = Field(..., max_length=20, description="联系方式")
    service_direction: str = Field(..., max_length=100, description="服务方向")
    area_id: int = Field(..., description="地区ID")


class AgentCreate(AgentBase):
    """创建Agent模型"""
    pass


class AgentUpdate(BaseModel):
    """更新Agent模型"""
    name: Optional[str] = Field(None, max_length=100, description="机构名称")
    credit_code: Optional[str] = Field(None, max_length=20, description="统一社会信用代码")
    license_expire: Optional[date] = Field(None, description="执照有效期")
    business_scope: Optional[str] = Field(None, description="经营范围")
    legal_person: Optional[str] = Field(None, max_length=50, description="法人")
    phone: Optional[str] = Field(None, max_length=20, description="联系方式")
    service_direction: Optional[str] = Field(None, max_length=100, description="服务方向")
    area_id: Optional[int] = Field(None, description="地区ID")
    is_approved: Optional[bool] = Field(None, description="审核状态")


class AgentResponse(AgentBase):
    """Agent响应模型"""
    id: int
    trainee_count: int = Field(default=0, description="培训人数")
    training_sessions: int = Field(default=0, description="培训人次")
    is_approved: bool = Field(default=False, description="审核状态")
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True


class AgentDetail(AgentResponse):
    """Agent详细信息模型"""
    area_name: Optional[str] = Field(None, description="地区名称")


class AgentListResponse(BaseModel):
    """Agent列表响应模型"""
    total: int
    page: int
    page_size: int
    data: List[AgentDetail]


class AgentApprovalRequest(BaseModel):
    """Agent审核请求模型"""
    is_approved: bool = Field(..., description="审核状态")
    notes: Optional[str] = Field(None, description="审核备注")